import { createRouter, createWebHistory } from 'vue-router'
import getPageTitle from "@/utils/GetPageTitle"; 

const routes = [
  {
    path: '/',
    name: 'framework',
    component: () => import('@/Framework.vue'),
    redirect: '/index',
    children:[
      {
        path:'/index',
        name:'index',
        component:()=>import('@/views/Index.vue'),
        meta:{
          title:'首页'
        }
      },
      {
        path:'/blog',
        name:'blog',
        component:()=>import('@/views/Blog.vue'),
        meta:{
          title:'博客'
        }
      },
      {
        path:'/blog/:blogId',
        name:'blogDetail',
        component:()=>import('@/views/BlogDetail.vue'),
        meta:{
          title:'博客详情'
        }
      },
      {
        path:'/category',
        name:'category',
        component:()=>import('@/views/Category.vue'),
        meta:{
          title:'分类专栏'
        }
      },
      {
        path:'/category/:categoryId',
        name:'categoryDetail',
        component:()=>import('@/views/CategoryDetail.vue'),
        meta:{
          title:'分类专栏详情'
        }
      },
      {
        path:'/special',
        name:'special',
        component:()=>import('@/views/Special.vue'),
        meta:{
          title:'专题'
        }
      },
      {
        path:'/special/:categoryId',
        name:'specialDetail',
        component:()=>import('@/views/SpecialDetail.vue'),
        meta:{
          title:'专题详情'
        }
      },
      {
        path:'/users',
        name:'users',
        component:()=>import('@/views/User.vue'),
        meta:{
          title:'成员'
        }
      },
      {
        path:'/user/:userId',
        name:'userDetail',
        component:()=>import('@/views/UserDetail.vue'),
        meta:{
          title:'用户详情'
        }
      },
      {
        path:'/message',
        name:'message',
        component:()=>import('@/views/Message.vue'),
        meta:{
          title:'留言板'
        }
      },
    ]
  }
]

const router = createRouter({
  routes,
  history: createWebHistory()
})

router.beforeEach((to, _, next) => {
  document.title = getPageTitle(to.meta.title);
  next()
})


export default router
